<?php
class Control_Gm_selectMulUserInfo {
	function selectMulUserInfo() {
		
		$action = MooForm::request('action');
		$view = MooForm::request('view');
		
		$gifts = MooConfig::get('gm_gift');
		$giftData = "";
		if($gifts) {
			foreach ($gifts as $key => $val) {
				if($giftData == "") {
					$giftData = $key;
				} else {
					$giftData .= "|" . $key ;
				}
			}
		}
		
		// 		$giftData = "hello|13612345564|13825646464|13412236054|13012348564|13012345564|13012365564|彭小|王达||王飞|李相公|王二|李四|李五|周欢欢|钻石100|钻石500|钻石1000|金币100|金币500|金币1000|";
		MooView::set('sourceData', $giftData);
		
		$gm_awardsinfo = MooConfig::get('gm_awardstype.type');
		MooView::set('gm_awardsinfo', $gm_awardsinfo);
		
		if(!$view) {
			$view = 1;
		}
		MooView::set('view', $view);
		
		$userOperation = MooConfig::get('useroperation.action');
		MooView::set('num', count($userOperation));
		MooView::set('userOperation', $userOperation);
		
		$serverOperation = MooConfig::get('serveroperation.action');
		
		MooView::set('num2', count($serverOperation));
		MooView::set('serverOperation', $serverOperation);
		
		if($action == 0) {
			
			$nowGame = MooConfig::get('main.defaultGame');
			$servers = MooConfig::get('server.' . $nowGame);
			
			MooView::set('nowGame', $nowGame);
			MooView::render("gm_selectUserInfo");
		}else {
			
			$lang = MooConfig::get('lang.zh');
			
			$userName = MooObj::get('User')->getUserName();
			$getGame = $game 	= MooForm::request('game');
			// 设置平台信息
			$gameLangConf = MooConfig::get('game_lang.zh_en');
			if($gameLangConf[$game]) {
				$game = $gameLangConf[$game];
			}
			
			$channelInfo = MooObj::get('Game')->getPlatformByGame($game);
			
			if($channelInfo) {
				MooView::set('channelInfo', $channelInfo);
			}
			
			$params = array();
			$getplayerIds 	= MooForm::request('playerIds');
			$playerIds = explode(",", $getplayerIds);
			
			$server 	= MooForm::request('serverUrl');
			$serverLists = MooObj::get('Gm')->getServerListByGame($game);
			
			$channels = array();
			if($serverLists) {
				foreach($serverLists as $key=> $val) {
					if(!in_array($val['platform'], $channels)) {
						$channels[] = $val['platform'];
					}
					
				}
			}
			if($channels) {
				foreach($channels as $k => $v) {
					MooView::set('channel_'.$k,  $v);
				}
			}
			
			if($serverLists) {
				$serverUrl = $serverLists[$server]['url'];
			}
			
			$cmd = "playerinfo";
			$playerInfos = array();
			if($playerIds) {
				foreach ($playerIds as $key => $playerId) {
					$params['playerid'] = $playerId;
					$url = MooObj::get('Gm')->getUrl($serverUrl, $cmd, $userName, $params);
					$data = MooUtil::curl_send($url);
					
					$info = array();
					if($data === false) {
						$info['status'] = -1; // 服务器连接不上
					} else {
						$result = MooJson::decode($data, true);
						$info = $result;
					}
					
					if($info['status'] == 1) {
						$info['status'] = "信息正常";
					} else if ($info['status'] == 0) {
						$info['status'] = "用户不存在";
						$info['id'] = $playerId;
					} else if ($info['status'] == -1) {
						$info['status'] = "服务器连接失败";
						$info['id'] = $playerId;
					}
					
					$playerInfos[] = $info;
				}
			}
			
			MooView::set('nowGame', $getGame);
			
			MooView::set('test_playerId', $getplayerIds);
			MooView::set('test_playerInfos', $playerInfos);
			
			MooView::set('playerIds', $getplayerIds);
			MooView::set('playerInfos', $playerInfos);
			
			MooView::set('nowServer', $server);
			MooView::set('serverLists', $serverLists);
			MooView::render("gm_selectUserInfo");
		}
	}
}